<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>

		var memoize = function (fn) {
			var cache = {};
			return function () {
				var args_str = JSON.stringify(arguments);
				cache[args_str] = cache[args_str] || fn.apply(fn, arguments)
				debugger;
				return cache[args_str]
			}
		}


		var squareNumber = memoize((x) => x * x)
		var xyAdd = memoize((x, y) => x + y)


		squareNumber(4) //4=>4*4=16
		squareNumber(4) //4=>16
		xyAdd(3, 4) //3,4=>x+y=7
		xyAdd(3, 4) //3,4=>7
	</script>
</body>

</html>